from django.db import models
from user.models import UserModel


# Create your models here.

class ImgModel(models.Model):
    img_path = models.CharField(max_length=256, verbose_name="图片地址")
    desc = models.CharField(max_length=128, verbose_name="图片描述")

    class Meta:
        db_table = "img"


# 商品分类
class CateModel(models.Model):
    name = models.CharField(max_length=32, verbose_name="分类名称")

    class Meta:
        db_table = "cate"


# 商品
class GoodsModel(models.Model):
    sku_name = models.CharField(max_length=100, verbose_name='商品名字')
    price = models.DecimalField(max_digits=13, decimal_places=2, verbose_name="商品价格")
    selling_price = models.DecimalField(max_digits=13, decimal_places=2, verbose_name="商品销售价格")
    img = models.CharField(max_length=200, verbose_name="商品默认图片")
    title = models.CharField(max_length=30, verbose_name="商品标题", null=True)
    instruction = models.TextField(verbose_name="商品的描述信息")
    count = models.IntegerField(verbose_name="商品销售数量", default=0)
    stock = models.IntegerField(verbose_name="商品库存数量", default=0)
    cate = models.ForeignKey(CateModel, on_delete=models.CASCADE, verbose_name='商品类别')
    online = models.BooleanField("是否在售", default=True)

    class Meta:
        db_table = "goods"


# 商品图片
class GoodsImgModel(models.Model):
    img_path = models.CharField(max_length=256, verbose_name="商品图片地址")
    desc = models.CharField(max_length=256, verbose_name="图片描述")
    goods = models.ForeignKey(GoodsModel, on_delete=models.CASCADE, verbose_name="商品")

    class Meta:
        db_table = "goods_img"


# 收藏
class GoodsCollectModel(models.Model):
    user = models.ForeignKey(to=UserModel, on_delete=models.CASCADE, verbose_name="用户")
    goods = models.ForeignKey(GoodsModel, on_delete=models.CASCADE, verbose_name="商品")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="收藏时间")

    class Meta:
        db_table = "goods_collect"
